import instance from '@/axios/config.js';

export default {
  //get请求
  getByparams (url, params = {}) {
    return new Promise((resolve, reject) => {
      instance.get(url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //get请求不带参数
  get (url) {
    return new Promise((resolve, reject) => {
      instance.get(url).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //post请求
  post (url, params = {}) {
    return new Promise((resolve, reject) => {
      instance.post(url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //put请求
  put (url, params = {}) {
    return new Promise((resolve, reject) => {
      instance.put(url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //delete请求
  delete (url, params = {}) {
    return new Promise((resolve, reject) => {
      instance.delete(url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}
